package com.work.game.home.ui.activity;


import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.work.game.R;
import com.work.game.ad.MediationSplashAd;
import com.work.game.ad.inter.RewardAdSplasInter;
import com.work.game.ad.kaku.TaKuSplashAd;
import com.work.game.home.HorizontalNtbActivity;
import com.work.game.home.ui.enums.RedisEnum;
import com.work.game.volley.BaseActivity;

public class SplashGmActivity extends BaseActivity implements RewardAdSplasInter {
    private FrameLayout llShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_splash_gm);
        super.onCreate(savedInstanceState);
        //设置系统状态背景色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.white));
        }
        ImageView logo = findViewById(R.id.splash_logo);
        Glide.with(this).load(R.drawable.icon_logo).into(logo);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        loading();
        String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
        if (RedisEnum.TA_KU.getValue().equals(key)) {
            TaKuSplashAd taKuSplashAd = TaKuSplashAd.getInstance();
            taKuSplashAd.setToken(getSharedPreferences("deviceId"));
            taKuSplashAd.setmActivity(this);
            taKuSplashAd.load(this, getSharedPreferences(RedisEnum.SPREAD_ITS_TAIL.getKey()), this,llShow);
        } else {
            MediationSplashAd mediationSplashAd = MediationSplashAd.getInstance();
            mediationSplashAd.setRewardAdSplasInter(this);
            mediationSplashAd.setActivity(this);
            mediationSplashAd.showCacheSplashAd(llShow);
        }
    }

    @Override
    public void initView() {
        super.initView();
        llShow = findViewById(R.id.ll_show);
    }

    //GM
    @Override
    public void onError() {
        loadDismiss();
        sendIntent(SplashGmActivity.this, HorizontalNtbActivity.class);
        finish();
    }

    @Override
    public void onAdClose() {
        loadDismiss();
        sendIntent(SplashGmActivity.this, HorizontalNtbActivity.class);
        finish();
    }

    @Override
    public void closeAlert() {
        loadDismiss();
    }
}